<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/4 0004
 * Time: 10:19
 */
//留言板
include 'publics.php';
//留言内容查询
if(isset($_GET['m_id'])){
    $m_id =  $_GET['m_id'];
    $sql = "select * from message where m_id =".$m_id ;
    $data = find($sql);

//重组数组，将发送人和接收人装入
    $aql1 = "select username from user where u_id = ".$data['put_user_id'];
    $user1 = find($aql1);
    $data['put_username'] = $user1['username'];
    $aql2 = "select username from user where u_id = ".$data['get_user_id'];
    $user2 = find($aql2);
    $data['get_username'] = $user2['username'];

    if(!empty($_POST)){
        $txet = $_POST['text'];
        $m_ids = $_POST['m_id'];
        $sql = "update message set text = '".$txet."' where m_id = ".$m_ids ;
        $data = insert($sql);
        if($data == true){
            heads('修改成功！',3,'message.php');
        }else{
            heads('修改失败！',3,'message.php');
        }
    }
}else{
    header('Refresh: 0; url= message.php');
}
//
function heads($das,$num,$url){
    echo '<script type="text/javascript">';
    echo 'alert("'.$das.'")';
    echo '</script>';
    header('Refresh: '.$num.'; url='.$url.'');
    exit;
}
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改</title>
</head>
<body>
<div class="top_all">
    <form action="update.php" method="post">
        <div style="width: 200px;color: blue"><span>发送人：</span><?php echo $data['put_username']?></div>
        <div style="width: 200px;color: green"><span>接收人：</span><?php echo $data['get_username']?></div>
        <span>内容：</span><textarea name="text" id="" cols="30" rows="10" placeholder="<?php echo $data['text']?>"></textarea>
        <div style="width: 400px;color: black"><span>时间：</span><?php echo date("Y-m-d H:i:s",$data['crete_time']); ?></div>
        <input type="hidden" name="m_id" value="<?php echo $data['m_id'] ;?>">
        <input type="submit" value="修改">
    </form>

    <a href="message.php">返回</a>
</div>
<br>
</body>
</html>
